package com.hsjk.szwj.module.train.dal.mysql.product;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.hsjk.szwj.framework.mybatis.core.mapper.BaseMapperX;
import com.hsjk.szwj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuBindDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSpuDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface IProductSkuBindMapper extends BaseMapperX<ProductSkuBindDO> {

    default ProductSkuDO selectSkuByCourseId(Long courseId) {
        return selectJoinOne(ProductSkuDO.class, new MPJLambdaWrapper<ProductSkuBindDO>()
                .eq(ProductSkuBindDO::getBindId, courseId)
                .eq(ProductSkuBindDO::getBindType, 1)
                .eq(ProductSpuDO::getSpuType, 2)
                .selectAll(ProductSkuDO.class)
                .leftJoin(ProductSkuDO.class, ProductSkuDO::getId, ProductSkuBindDO::getSkuId)
                .leftJoin(ProductSpuDO.class, ProductSpuDO::getId, ProductSkuDO::getSpuId)
        );
    }

    default List<ProductSkuBindDO> selectListBySkuId(Long skuId) {
        return selectList(new MPJLambdaWrapper<ProductSkuBindDO>()
                .eq(ProductSkuBindDO::getSkuId, skuId));
    }

    default List<ProductSkuBindDO> getProductSkuBindListByCourseId(Long courseId) {
        return selectList(new LambdaQueryWrapperX<ProductSkuBindDO>()
                .eq(ProductSkuBindDO::getBindId, courseId));
    }
}
